<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" codefile="ScheduleMatch.aspx.vb" Inherits="ScheduleMatch" %>

<asp:Content id="content1" ContentPlaceHolderID="mainContent" runat="server">
    <asp:sqldatasource id="FixturesDataSource" runat="server" connectionstring="<%$ ConnectionStrings:WroxUnited %>"
        selectcommand="SELECT [FixtureID], [FixtureDate], [FixtureType], [Notes], [Opponents] FROM [Fixtures] ORDER BY [FixtureDate]"
        deletecommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @original_FixtureID AND [FixtureDate] = @original_FixtureDate AND [FixtureType] = @original_FixtureType AND [Notes] = @original_Notes AND [Opponents] = @original_Opponents"
        insertcommand="INSERT INTO [Fixtures] ([FixtureDate], [FixtureType], [Notes], [Opponents]) VALUES (@FixtureDate, @FixtureType, @Notes, @Opponents)"
        updatecommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [FixtureType] = @FixtureType, [Notes] = @Notes, [Opponents] = @Opponents WHERE [FixtureID] = @original_FixtureID AND [FixtureDate] = @original_FixtureDate AND [FixtureType] = @original_FixtureType AND [Notes] = @original_Notes AND [Opponents] = @original_Opponents"
        conflictdetection="CompareAllValues">
        <DeleteParameters>
            <asp:Parameter Type="Int32" Name="FixtureID"></asp:Parameter>
            <asp:Parameter Type="DateTime" Name="FixtureDate"></asp:Parameter>
            <asp:Parameter Type="String" Name="FixtureType"></asp:Parameter>
            <asp:Parameter Type="String" Name="Notes"></asp:Parameter>
            <asp:Parameter Type="String" Name="Opponents"></asp:Parameter>
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Type="DateTime" Name="FixtureDate"></asp:Parameter>
            <asp:Parameter Type="String" Name="FixtureType"></asp:Parameter>
            <asp:Parameter Type="String" Name="Notes"></asp:Parameter>
            <asp:Parameter Type="String" Name="Opponents"></asp:Parameter>
            <asp:Parameter Type="Int32" Name="FixtureID"></asp:Parameter>
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Type="DateTime" Name="FixtureDate"></asp:Parameter>
            <asp:Parameter Type="String" Name="FixtureType"></asp:Parameter>
            <asp:Parameter Type="String" Name="Notes"></asp:Parameter>
            <asp:Parameter Type="String" Name="Opponents"></asp:Parameter>
        </InsertParameters>
    </asp:sqldatasource>
    <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" datasourceid="FixturesDataSource"
        datakeynames="FixtureID" allowsorting="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:CommandField ShowSelectButton="True"></asp:CommandField>
            <asp:BoundField ReadOnly="True" HeaderText="FixtureID" InsertVisible="False" DataField="FixtureID" SortExpression="FixtureID" Visible="False"></asp:BoundField>
            <asp:BoundField HeaderText="Date" DataField="FixtureDate" SortExpression="FixtureDate" DataFormatString="{0:ddd dd-MMM-yy}"></asp:BoundField>
            <asp:BoundField HeaderText="Fixture Type" DataField="FixtureType" SortExpression="FixtureType"></asp:BoundField>
            <asp:BoundField HeaderText="Opponents" DataField="Opponents" SortExpression="Opponents"></asp:BoundField>
        </Columns>
    </asp:gridview>
    <asp:Button ID="NewMatch" runat="server" CssClass="buttonLink" Text="New Match" />
    <br />
    
    <asp:sqldatasource id="FixtureRWDataSource" runat="server" connectionstring="<%$ ConnectionStrings:WroxUnited %>"
        selectcommand="SELECT [FixtureID], [FixtureDate], [FixtureType], [Notes], [Opponents] FROM [Fixtures] WHERE ([FixtureID] = @FixtureID)"
        deletecommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @original_FixtureID"
        insertcommand="INSERT INTO [Fixtures] ([FixtureDate], [FixtureType], [Notes], [Opponents]) VALUES (@FixtureDate, @FixtureType, @Notes, @Opponents)"
        updatecommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [FixtureType] = @FixtureType, [Notes] = @Notes, [Opponents] = @Opponents WHERE [FixtureID] = @original_FixtureID"
        conflictdetection="CompareAllValues">
        <DeleteParameters>
            <asp:Parameter Name="original_FixtureID"></asp:Parameter>
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Type="DateTime" Name="FixtureDate"></asp:Parameter>
            <asp:Parameter Type="String" Name="FixtureType"></asp:Parameter>
            <asp:Parameter Type="String" Name="Notes"></asp:Parameter>
            <asp:Parameter Type="String" Name="Opponents"></asp:Parameter>
            <asp:Parameter Name="original_FixtureID"></asp:Parameter>
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter Name="FixtureID" Type="Int32" ControlID="GridView1" PropertyName="SelectedValue"></asp:ControlParameter>
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Type="DateTime" Name="FixtureDate"></asp:Parameter>
            <asp:Parameter Type="String" Name="FixtureType"></asp:Parameter>
            <asp:Parameter Type="String" Name="Notes"></asp:Parameter>
            <asp:Parameter Type="String" Name="Opponents"></asp:Parameter>
        </InsertParameters>
        </asp:sqldatasource>
    
    <asp:SqlDataSource id="OpponentsDataSource" runat="server" connectionstring="<%$ ConnectionStrings:WroxUnited %>"
        SelectCommand="SELECT [Name] FROM [Opponents] ORDER BY [Name]"></asp:SqlDataSource>
    <br />
    <asp:detailsview id="DetailsView1" runat="server" datasourceid="FixtureRWDataSource"
        datakeynames="FixtureID" autogeneraterows="False" autogenerateinsertbutton="true"
        OnItemDeleted="DetailsView1_ItemDeleted" OnItemInserted="DetailsView1_ItemInserted"
        OnItemUpdated="DetailsView1_ItemUpdated">
        <Fields>
            <asp:BoundField ReadOnly="True" HeaderText="FixtureID" InsertVisible="False" DataField="FixtureID" SortExpression="FixtureID" Visible="False"></asp:BoundField>
            <asp:TemplateField SortExpression="FixtureDate" HeaderText="Fixture Date">
                <EditItemTemplate>
                    <asp:Calendar id=Calendar1 runat="server" SelectedDate='<%# Bind("FixtureDate") %>'></asp:Calendar>
                </EditItemTemplate>
                <Itemtemplate>
                    <asp:Label runat="server" Text='<%# Bind("FixtureDate", "{0:dd-MMM-yy}") %>' id="lblFixtureDate"></asp:Label>
                </Itemtemplate>
                <InsertItemTemplate>
                    <asp:Calendar id=Calendar1 runat="server" SelectedDate='<%# Bind("FixtureDate") %>'></asp:Calendar>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="Opponents" HeaderText="Opponents">
                <EditItemTemplate>
                    <asp:DropDownList id=DropDownList2 runat="server" DataSourceID="OpponentsDataSource" SelectedValue='<%# Bind("Opponents") %>' DataValueField="Name" DataTextField="Name"></asp:DropDownList> 
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("Opponents") %>' id="Label3"></asp:Label>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList id=DropDownList2 runat="server" DataSourceID="OpponentsDataSource" SelectedValue='<%# Bind("Opponents") %>' DataValueField="Name" DataTextField="Name"></asp:DropDownList> 
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="FixtureType" HeaderText="FixtureType">
                <EditItemTemplate>
                    <asp:DropDownList id=DropDownList1 runat="server" SelectedValue='<%# Bind("FixtureType") %>'>
                        <asp:ListItem Selected="True">League</asp:ListItem>
                        <asp:ListItem>Cup</asp:ListItem>
                        <asp:ListItem>Friendly</asp:ListItem>
                    </asp:DropDownList> 
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("FixtureType") %>' id="Label2"></asp:Label>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList id=DropDownList1 runat="server" SelectedValue='<%# Bind("FixtureType") %>'>
                        <asp:ListItem Selected="True">League</asp:ListItem>
                        <asp:ListItem>Cup</asp:ListItem>
                        <asp:ListItem>Friendly</asp:ListItem>
                    </asp:DropDownList> 
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="Notes" HeaderText="Notes"><EditItemTemplate>
                    <asp:TextBox id=TextBox1 runat="server" Text='<%# Bind("Notes") %>' Columns="50" Rows="5" TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("Notes") %>' id="Label1"></asp:Label>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox id=TextBox1 runat="server" Text='<%# Bind("Notes") %>' Columns="50" Rows="5" TextMode="MultiLine"></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:detailsview></asp:Content>